package com.situ.ymall.intercepter;

import com.situ.ymall.entity.OrderDetails;
import com.situ.ymall.service.OrderDetailService;
import com.situ.ymall.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 清理无效订单的
 *
 */
@Component
public class CleanOrderIntercepter implements HandlerInterceptor {
    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderDetailService orderDetailService;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 清理无效订单
        orderService.clean();

        orderDetailService.clean();
        // 放行
        return true;
    }
}
